package com.ddone.mode.pubsub;

import com.ddone.util.RabbitMqConnectionUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author ddone
 * @date 2024/4/4-19:45
 */
public class FanoutPublisher {

    private final static String EXCHANGE_NAME = "fanout_exchange";

    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = RabbitMqConnectionUtil.getConnection();

        Channel channel = connection.createChannel();

        channel.exchangeDeclare(EXCHANGE_NAME, "fanout");

        String msg = "Hello Fanout Mode";

        channel.basicPublish(EXCHANGE_NAME,"",null,msg.getBytes());

        System.out.println(" [生产者] Sent '"+msg+" '");

        channel.close();
        connection.close();

    }
}
